home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / ACKSRC.ZIP / ACKASM.240 < prev    next >
Text File  |  1993-06-19  |  16KB  |  618 lines

  1. PAGE 80,132
  2. TITLE - XTASM.ASM - Assembly routines for 3D engine
  3. ;;;.286P
  4. ;==============================================================================
  5. ; COMMAND LINE ASSEMBLY
  6. ;    MASM /B63 /Z /D_Mx FILENAME;
  7. ;
  8. ;  WHERE Mx SPECIFIES MODEL (l OR c) FOR LARGE OR COMPACT MODELS
  9. ;==============================================================================
  10.     INCLUDE        ET.EQU
  11.     INCLUDE        ET.MAC
  12.  
  13.     ANGLE_30    equ        160
  14.     ANGLE_360   equ        1920
  15.  
  16.     extrn    _bMaps:DWORD
  17.     extrn    _oMaps:DWORD
  18.     extrn    _bdfp:DWORD
  19.     extrn    _PageBegin:WORD
  20.     extrn    _InvCosTable:DWORD
  21.     extrn    _InvSinTable:DWORD
  22.     extrn    _LongCosTable:DWORD
  23.     extrn    _DistanceTable:WORD
  24.     extrn    _AdjustTable:DWORD
  25.     extrn    _CenterRow:WORD
  26.     extrn    _MaxDistance:WORD
  27.     extrn    _TopColor:WORD
  28.     extrn    _BottomColor:WORD
  29.  
  30.     extrn    _lowmask:BYTE
  31.     extrn    _Walls:WORD
  32.  
  33.  
  34.     extrn    _xRay:NEAR
  35.     extrn    _yRay:NEAR
  36.     extrn    N_LDIV@:FAR
  37.  
  38.  
  39.     PUBLIC        _graphinit
  40.     PUBLIC        _usepage
  41.     PUBLIC        _flippage
  42.     PUBLIC        _SetPalette
  43.     PUBLIC        _DrawWalls
  44.     PUBLIC        _DrawOneObject
  45.  
  46. SC_INDEX equ    03c4h    ;Sequence Controller Index
  47. CRTC_INDEX equ    03d4h    ;CRT Controller Index
  48. MISC_OUTPUT equ 03c2h    ;Miscellaneous Output register
  49. SCREEN_SEG equ    0a000h    ;segment of display memory in mode X
  50.  
  51.  
  52. _TEXT    segment byte public 'CODE'
  53. DGROUP    group    _DATA,_BSS
  54.     assume    cs:_TEXT,ds:DGROUP
  55. _ViewPage  dw 0 ; The address of the current view page
  56. _WritePage dw 0 ; The address of the current write page
  57. PageTable dw 4 dup (0)     ; Address of 4 pages
  58. ScreenWidth dw 320/4     ; The width of the screen
  59. PageSize    dw 320/4*240 ; The size of each page
  60. CRTParms label    word
  61.           dw      00d06h  ;vertical total
  62.           dw      03e07h  ;overflow (bit 8 of vertical counts)
  63.           dw      04109h  ;cell height (2 to double-scan)
  64.           dw      0ea10h  ;v sync start
  65.           dw      0ac11h  ;v sync end and protect cr0-cr7
  66.           dw      0df12h  ;vertical displayed
  67.           dw      00014h  ;turn off dword mode
  68.           dw      0e715h  ;v blank start
  69.           dw      00616h  ;v blank end
  70.           dw      0e317h  ;turn on byte mode
  71. CRT_PARM_LENGTH equ    (($-CRTParms)/2)
  72.  
  73. _TEXT    ends
  74. _DATA    segment word public 'DATA'
  75. ; Index/data pairs for CRT Controller registers that differ between
  76. ; mode 13h and mode X.
  77. _d@    label    byte
  78. _DATA    ends
  79. _BSS    segment word public 'BSS'
  80. _b@    label    byte
  81. _BSS    ends
  82.  
  83.  
  84. public _graphinit
  85. public _ViewPage,_WritePage
  86. public ScreenWidth,PageSize,PageTable
  87.  
  88.  
  89. _TEXT    SEGMENT byte public 'CODE'
  90.     ASSUME cs:_TEXT
  91.  
  92. ;==============================================================================
  93. ; void graphinit(int width,int psize,int mask)
  94. ;   width - width of the screen in bytes/plane (defaults to 320/4 if 0)
  95. ;   psize - size of each page in bytes/plane (defaults to 320*200/4 if 0)
  96. ;==============================================================================
  97. PBEGIN     _graphinit
  98.      push bp
  99.      mov bp,sp
  100.      push si
  101.      push di
  102.      push ds
  103.  
  104.      mov ax,cs
  105.      mov ds,ax
  106.      mov es,ax
  107.  
  108.      mov bx,320/4
  109.      mov cs:[ScreenWidth],bx
  110.      mov bx,320/4*240
  111.     mov cs:[PageSize],bx
  112.  
  113.     ; Set up the page table
  114.  
  115.     xor ax,ax
  116.     mov bx,cs:[PageSize]
  117.     lea di,cs:[PageTable]
  118.     mov cx,4
  119. init4:
  120.     stosw
  121.     add ax,bx
  122.     loop init4
  123.  
  124. ;;;;;    mov    word ptr cs:[PageTable+2],8000H
  125.  
  126. ; Now set up the graphics mode
  127.  
  128.     mov ax,13h
  129.     int 10h ; Set 320x200x256
  130.  
  131.     mov dx,SC_INDEX
  132.     mov ax,0604h
  133.     out dx,ax    ;disable chain4 mode
  134.     mov ax,0100h
  135.     out dx,ax    ;synchronous reset while switching clocks
  136.  
  137.     mov dx,MISC_OUTPUT
  138.     mov al,0e3h
  139.     out dx,al    ;select 28 MHz dot clock & 60 Hz scanning rate
  140.  
  141.     mov dx,SC_INDEX
  142.     mov ax,0300h
  143.     out dx,ax    ;undo reset (restart sequencer)
  144.  
  145.     mov dx,CRTC_INDEX ;reprogram the CRT Controller
  146.     mov al,11h    ;VSync End reg contains register write
  147.     out dx,al    ; protect bit
  148.     inc dx    ;CRT Controller Data register
  149.     in al,dx   ;get current VSync End register setting
  150.     and al,7fh    ;remove write protect on various
  151.     out dx,al    ; CRTC registers
  152.     dec dx    ;CRT Controller Index
  153.     cld
  154.     mov si,offset CRTParms ;point to CRT parameter table
  155.     mov cx,CRT_PARM_LENGTH ;# of table entries
  156. SetCRTParmsLoop:
  157.     lodsw        ;get the next CRT Index/Data pair
  158.     out dx,ax    ;set the next CRT Index/Data pair
  159.     loop SetCRTParmsLoop
  160.  
  161.     mov dx,SC_INDEX
  162.     mov ax,0f02h
  163.     out dx,ax    ;enable writes to all four planes
  164.     mov ax,SCREEN_SEG ;now clear all display memory, 8 pixels
  165.     mov es,ax          ; at a time
  166.     sub di,di    ;point ES:DI to display memory
  167.     sub ax,ax    ;clear to zero-value pixels
  168.     mov cx,8000h ;# of words in display memory
  169.     rep stosw    ;clear all of display memory
  170.  
  171.     pop ds
  172.     pop di    ;restore C register vars
  173.     pop si
  174.     pop bp    ;restore caller's stack frame
  175.     ret
  176. _graphinit endp
  177.  
  178. ;==============================================================================
  179. ; void SetVGAmode(void);
  180. ;==============================================================================
  181. PBEGIN    _SetVGAmode
  182.     push    bp
  183.     mov    ax,13h
  184.     int    10h        ; Set 320x200x256
  185.     pop    bp
  186.     ret
  187. _SetVGAmode endp
  188.  
  189. ;==============================================================================
  190. ; void usepage(int page)
  191. ;==============================================================================
  192. UPnum    equ    [bp+ABASE]
  193.  
  194. PBEGIN    _usepage
  195.     push bp
  196.     mov bp,sp
  197.     mov bx,UPnum
  198.     and bx,3
  199.     shl bx,1
  200.     mov ax,cs:PageTable[bx]
  201.     mov cs:[_WritePage],ax
  202.     pop bp
  203.     ret
  204. _usepage endp
  205.  
  206. ;==============================================================================
  207. ; void flippage()
  208. ;
  209. ; NOTE: Some lines have been commented out for test purposes. If you experience
  210. ;    flicker when the page flips, un-comment the lines waiting for vertical
  211. ;    retrace.
  212. ;==============================================================================
  213. PBEGIN    _flippage
  214.     mov cx,cs:[_ViewPage]
  215.     xchg cx,cs:[_WritePage]
  216.     mov cs:[_ViewPage],cx ; An ISR will set the VGA at the next retrace
  217.  
  218.     mov  bh,0dH
  219.     mov  bl,cl
  220.     mov dx,3dah
  221.  
  222. Ret1:
  223. ;;;;    in al,dx
  224. ;;;;    test al,1
  225. ;;;;    jnz Ret1 ; Wait for display enable
  226.  
  227.  
  228.  
  229. ;    cli
  230.     mov al,0ch
  231.     mov ah,ch
  232.     mov dx,3d4h
  233.     out dx,ax    ; set the displayed offset (high)
  234. ;    inc al
  235. ;    mov ah,cl
  236. ;;;    mov ax,bx
  237. ;;;    out dx,ax    ; set the displayed offset (low)
  238. ;    sti
  239.  
  240. ;;    mov dx,3dah
  241. Ret2:
  242. ;;    in al,dx
  243. ;;    test al,8
  244. ;;    jz Ret2 ; Wait for the video card to use the address just set
  245.  
  246.     ret
  247. _flippage endp
  248.  
  249.  
  250. ;==============================================================================
  251. ; void SetPalette(unsigned char far *PalBuf);
  252. ;==============================================================================
  253. SPbuf    equ    [bp+ABASE]
  254.  
  255. PBEGIN    _SetPalette
  256.     push    bp
  257.     mov    bp,sp
  258.     push    ds
  259.     push    si
  260.  
  261.     lds    si,dword ptr SPbuf
  262.     mov    cx,256
  263.     xor    bx,bx
  264.     cld
  265.     mov    dx,3C8H
  266. sp010:
  267.     mov    al,bl
  268.     out    dx,al
  269.     inc    dx
  270.     lodsb
  271.     out    dx,al
  272.     lodsb
  273.     out    dx,al
  274.     lodsb
  275.     out    dx,al
  276.     dec    dx
  277.     inc    bx
  278.     loop    sp010
  279.  
  280.     pop    si
  281.     pop    ds
  282.     pop    bp
  283.     ret
  284. _SetPalette endp
  285.  
  286. ;==============================================================================
  287. ; void DrawWalls(void);
  288. ;==============================================================================
  289. Y2    equ    [bp-2]
  290. AVLOW    equ    [bp-4]
  291. AVHI    equ    [bp-6]
  292. VCOL    equ    [bp-8]
  293. BOFFLOW equ    [bp-10]
  294. BOFFHI    equ    [bp-12]
  295. sColor    equ    [bp-14]
  296. fColor    equ    [bp-16]
  297.  
  298. PBEGIN    _DrawWalls
  299.     push    bp
  300.     mov    bp,sp
  301.     sub    sp,18
  302.     push    ds
  303.     push    si
  304.     push    di
  305.  
  306.     mov    dx,3c4H
  307.     mov    ax,0F02H
  308.     out    dx,ax            ;Select map mask and all planes
  309.  
  310.     mov    bx,word ptr DGROUP:_MaxDistance ; Get max distance to wall
  311.     shl    bx,1            ; Make a word index
  312.     mov    ax,word ptr DGROUP:_DistanceTable[bx] ;Look up actual height
  313.     cmp    ax,240            ; Full screen height?
  314.     jae    drw000            ; Yes, nothing to fill in
  315.  
  316.     and    ax,0FFFEH        ; Strip any odd values
  317.     mov    bx,ax            ; Save height
  318.     mov    si,ax            ; Again save height
  319.     shr    bx,1            ; Get Height / 2                                                                                                                                     
  320.     mov    dx,120            ; Pick up our center row
  321.     sub    dx,bx            ; and sub ht/2
  322.     mov    bx,dx            ; Save new value
  323.     mov    cl,6            ; Get ready to mult by 80
  324.     shl    bx,cl            ; first mult by 64
  325.     shl    si,cl            ; also mult the original ht
  326.     mov    cl,4            ; No do a mult by 16
  327.     shl    dx,cl            ; to top layer
  328.     shl    ax,cl            ; and initial height
  329.     add    bx,dx            ; Add x64 and x16 for x80
  330.     add    si,ax            ; do same with height
  331.  
  332.     mov    ax,0A000H
  333.     mov    es,ax
  334.     mov    di,cs:_WritePage    ;get start of buffer
  335.  
  336.     mov    ax,ds:_TopColor
  337.     mov    ah,al
  338.     shr    bx,1            ;only fill words
  339.     mov    cx,b